package com.suixinsanren.design.compound.study.demo03;

/**
 * simulator()接收工厂对象，由工厂给他生产鸭子，而非自己new
 */
public class DuckSimulator {

    public static void main(String[] args) {
        DuckSimulator simulator = new DuckSimulator();
        AbstractDuckFactory duckFactory = new CountingDuckFactory();
        simulator.simulator(duckFactory);
    }

    public void simulator(AbstractDuckFactory duckFactory) {
        Quackable mallardDuck = duckFactory.createMallardDuck();
        Quackable redHeadDuck = duckFactory.createRedHeadDuck();
        Quackable duckCall = duckFactory.createDuckCall();
        Quackable rubberDuck = duckFactory.createRubberDuck();
        GooseAdapter goose = new GooseAdapter(new Goose());

        System.out.println("--------Duck Simulator : with Abstract Factory--------");

        simulator(mallardDuck);
        simulator(redHeadDuck);
        simulator(duckCall);
        simulator(rubberDuck);
        simulator(goose);

        System.out.println("The ducks quacked " + QuackCounter.getQuacks() + " times");
    }


    public void simulator(Quackable duck) {
        duck.quack();
    }
}
